package pms.views;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.part.ViewPart;

public class AllPatients extends ViewPart {
	public static final String VIEW_ID = "pms.views.allPatients";
	
	public AllPatients() {
		
	}

	@Override
	public void createPartControl(Composite parent) {
		TableViewer allPatientsTblVwr = new TableViewer(parent);
		
		// setting the tables ui customizations.
		Table allPatientTbl = allPatientsTblVwr.getTable();
		allPatientTbl.setHeaderVisible(true);		// column headers
		allPatientTbl.setLinesVisible(true);		// row lines
		
		allPatientsTblVwr.setLabelProvider(new MyLabelProvider());
		allPatientsTblVwr.setContentProvider(new MyContentProvider());
		
		TableColumn column = new TableColumn(allPatientsTblVwr.getTable(),SWT.NONE);
		column.setWidth(200);
		column.setText("Column 1");
		
		column = new TableColumn(allPatientsTblVwr.getTable(),SWT.NONE);
		column.setWidth(200);
		column.setText("Column 2");
		
		MyModel[] model = createModel();
		allPatientsTblVwr.setInput(model);
		
	}
	
	@Override
	public void setFocus() {
		
	}
	
	private class MyContentProvider implements IStructuredContentProvider {

		/* (non-Javadoc)
		 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
		 */
		public Object[] getElements(Object inputElement) {
			return (MyModel[])inputElement;
		}

		/* (non-Javadoc)
		 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
		 */
		public void dispose() {
			
		}

		/* (non-Javadoc)
		 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
		 */
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			
		}
		
	}
	public class MyLabelProvider extends LabelProvider implements ITableLabelProvider {

		public Image getColumnImage(Object element, int columnIndex) {
			return null;
		}

		public String getColumnText(Object element, int columnIndex) {
			return "Column " + columnIndex + " => " + element.toString();
		}
		
	}
	public class MyModel {
		public int counter;
		
		public MyModel(int counter) {
			this.counter = counter;
		}
		
		public String toString() {
			return "Item " + this.counter;
		}
	}
	private MyModel[] createModel() {
		MyModel[] elements = new MyModel[10];
		
		for( int i = 0; i < 10; i++ ) {
			elements[i] = new MyModel(i);
		}
		
		return elements;
	}

}
